<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
</head>
<style>
    /* 子页面iframe样式 */
    .subpage-iframe {
        /* 确保iframe占满父容器 */
        display: block;
        min-height: 100%;
    }

    .timeLine {
        width: 100%;
        display: -webkit-flex;
        display: flex;
        flex-direction: row;
    }

    .timeLineImg {
        width: 20%;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .timeLineLeft {
        height: 100%;
        width: 2px;
        border-left: 1px solid #B0B0B0;
    }

    .timeLineInfo {
        width: 80%;
    }

    .timeLineInfoTitle {
        font-size: 20px;
        color: #3f51b5;
    }

    .timeLineInfoIntroduce {
        font-size: 16px;
        color: #0062cc;
    }

    .timeLineInfoTime {
        font-size: 12px;
        color: #CA92C4;
    }

    .scoll {
        overflow: auto;
        margin-top: 65px;
    }

    .aui-list .aui-list-item:after {
        width: 100%;
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: auto;
        right: auto;
        bottom: 0;
        left: 0;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-list:before {
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: 0;
        left: 0;
        right: auto;
        bottom: auto;
        width: 100%;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-card-list-header {
        color: #212121;
        font-size: 22px;
        font-weight: 600;
    }

    #addEmpBtn:before {
        content: url(../image/pn.png);
    }

    #addMrlBtn:before {
        content: url(../image/pn.png);
    }

    .radio-group {
        display: flex;
        align-items: center;
        margin: 10px 0;
        gap: 20px;
    }

    .radio-item {
        display: flex;
        align-items: center;
        gap: 5px;
    }

    input[type="radio"] {
        width: 16px;
        height: 16px;
    }

    /* 时间线 */
    .time-line-container {
        padding: 15px;
        position: relative;
        margin-left: 90px;
        /* 为左侧人员信息预留空间 */
    }

    .time-line-item {
        display: flex;
        margin-bottom: 40px;
        /* 增加间距，为连接线留出空间 */
        position: relative;
        align-items: center;
    }

    /* 左侧人员信息 */
    .time-line-person {
        width: 90px;
        position: absolute;
        left: -105px;
        /* 定位到圆点左侧 */
        text-align: right;
        font-weight: 600;
        color: #333;
        font-size: 15px;
    }

    /* 中间的圆点 - 固定尺寸确保圆心位置一致 */
    .time-line-dot {
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background-color: #ccc;
        margin-right: 18px;
        z-index: 2;
        /* 确保圆点在连接线之上 */
        position: relative;
    }

    .time-line-dot.active {
        background-color: #49A0E4;
        box-shadow: 0 0 0 3px rgba(73, 160, 228, 0.2);
    }

    /* 圆点之间的连接线 - 精确与圆心对齐 */
    .time-line-item:not(:last-child)::after {
        content: '';
        position: absolute;
        /* 计算圆心位置：left = 圆点宽度的一半 = 18px/2 = 9px */
        left: 9px;
        top: 25px;
        /* 从圆点底部开始（与圆点直径相同） */
        bottom: -100px;
        /* 到下一个圆点顶部结束 */
        width: 1px;
        background-color: #ddd;
        z-index: 1;
    }

    /* 右侧信息区域 */
    .time-line-info {
        background-color: #f9f9f9;
        padding: 12px 15px;
        border-radius: 6px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        flex: 1;
    }

    .time-line-status {
        display: flex;
        margin-bottom: 5px;
        flex-wrap: wrap;
    }

    .time-line-status-type {
        color: #666;
        margin-right: 8px;
        font-size: 14px;
        font-weight: 500;
    }

    .time-line-status-desc {
        color: #333;
        font-size: 14px;
    }

    .time-line-time {
        color: #999;
        font-size: 12px;
        margin-top: 3px;
    }
</style>

<body>
    <div style="height:114px;width:100%;position: fixed;top: 0px;bottom: auto;table-layout: fixed;z-index: 10;">
        <!-- <header class="aui-bar aui-bar-nav ui-selectee">维修单详情</header> -->
        <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
            <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title" id="title">
                维修单详情
            </div>
        </header>
        <div class="aui-tab aui-border-b" id="tab" style="margin-top:50px;">
            <div class="aui-tab-item aui-active">设备故障</div>
            <div class="aui-tab-item">处理意见</div>
            <div id="selectedMrl" class="aui-tab-item" style="display:none">更换备件</div>
            <div class="aui-tab-item">处理过程</div>
        </div>
    </div>
    <div class="aui-padded-5 " id="tab1-con" style="margin-top: 90px;">
        <div id="tab1-con1">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list ui-selectee">
                        <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                            <ul class="aui-list aui-form-list"
                                style="content: none;line-height: 3.5rem;font-size: 17px;">
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner" style="height: 25px;">
                                        <div class="aui-list-item-label ui-selectee">维修单号</div>
                                        <div class="aui-list-item-input ui-selectee">
                                            <input type="text" readonly id="faultOrderNo" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item" style="content: none;">
                                    <div class="aui-list-item-inner" style="height: 25px;">
                                        <div class="aui-list-item-label">设备编码</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipCode" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner" style="height: 25px;">
                                        <div class="aui-list-item-label">设备名称</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipName" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner" style="height: 25px;">
                                        <div class="aui-list-item-label">规格型号</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipModel" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner" style="height: 25px;">
                                        <div class="aui-list-item-label">设备类型</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="equipmentType" value="" />
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner" style="height: 25px;">
                                        <div class="aui-list-item-label">设备位置</div>
                                        <div class="aui-list-item-input">
                                            <input type="text" readonly id="ext09" value="" />
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                        <ul class="aui-list aui-form-list" style="content: none;line-height: 3.5rem;font-size: 17px;">
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner" style="height: 25px;">
                                    <div class="aui-list-item-label ui-selectee">故障描述</div>
                                    <div class="aui-list-item-input ui-selectee">
                                        <input type="text" readonly id="description" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner" style="height: 25px;">
                                    <div class="aui-list-item-label ui-selectee">报修人</div>
                                    <div class="aui-list-item-input ui-selectee">
                                        <input type="text" readonly id="ext06" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner" style="height: 25px;">
                                    <div class="aui-list-item-label" style="width: 45%;">发生时间</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="faultdate1" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner" style="height: 25px;">
                                    <div class="aui-list-item-label" style="width: 45%;">报修时间</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="faultdate2" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner" style="height: 25px;">
                                    <div class="aui-list-item-label">紧急程度</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="ext16" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label">--------------------</div>

                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- 处理意见 -->
        <div class="aui-hide" id="tab1-con2">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list ui-selectee">
                        <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                            <ul class="aui-list aui-form-list" style="content: none;">
                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label" style="width: 45%;">开始时间</div>
                                        <div class="aui-list-item-input" style="padding-top: 0.75rem;">
                                            <input class="form-control" type="datetime-local" step="1" id="beginDate"
                                                placeholder="请选择">
                                        </div>
                                    </div>
                                </li>
                                <li class="aui-list-item"
                                    style="border-bottom: 1px solid #eee; padding-bottom: 1px; margin-bottom: 1px;">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label" style="width: 45%;">结束时间</div>
                                        <div class="aui-list-item-input" style="padding-top: 0.75rem;">
                                            <input class="form-control" type="datetime-local" step="1" id="endDate"
                                                placeholder="请选择" onclick="calculateTimeDifference">
                                            <!-- <input  class="form-control" type="text" id="endDate"
                                             placeholder="请选择"> -->
                                        </div>
                                    </div>
                                </li>
                                <li class=" aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">维修用时</div>
                                        <div class="aui-list-item-input ui-selectee">
                                            <input type="text" id="ext04hour" style="display:inline-block; width:30px;">
                                            小时
                                            <input type="text" id="ext04min" style="display:inline-block; width:30px;">
                                            分钟
                                        </div>
                                    </div>
                                </li>

                                <li class=" aui-list-item">
                                    <div class="aui-list-item-label ui-selectee" style="width: 45%;">是否停机</div>
                                    <div class="aui-list-item-input ui-selectee">
                                        <div class="radio-group">
                                            <div class="radio-item">
                                                <input type="radio" name="ext15" id="ext15是" value="是" checked
                                                    onchange="changeExt15()">
                                                <label for="ext15">是</label>
                                            </div>
                                            <div class="radio-item">
                                                <input type="radio" name="ext15" id="ext15否" value="否"
                                                    onchange="changeExt15()">
                                                <label for="ext15">否</label>
                                            </div>
                                        </div>
                                    </div>
                                </li>

                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label ui-selectee" style="width: 45%;">停机时长</div>
                                        <div class="aui-list-item-input ui-selectee">
                                            <input type="text" id="ext17hour" style="display:inline-block; width:30px;">
                                            小时
                                            <input type="text" id="ext17min" style="display:inline-block; width:30px;">
                                            分钟
                                        </div>
                                    </div>
                                </li>

                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">维修状态</div>
                                        <div class="aui-list-item-input">
                                            <select id="ext28" placeholder="请选择">
                                            </select>
                                        </div>
                                    </div>
                                </li>

                                <li class="aui-list-item">
                                    <div class="aui-list-item-inner">
                                        <div class="aui-list-item-label">故障类别</div>
                                        <div class="aui-list-item-input">
                                            <select id="faultClass" placeholder="请选择">
                                            </select>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                        <ul class="aui-list aui-form-list" style="content: none;">

                            <li class="aui-list-item">
                                <div class="aui-list-item-label ui-selectee" style="width: 45%;">是否更换配件</div>
                                <div class="aui-list-item-input ui-selectee">
                                    <div class="radio-group">
                                        <div class="radio-item">
                                            <input type="radio" name="ext08" id="ext08是" value="是"
                                                onchange="changeExt08()">
                                            <label for="ext08">是</label>
                                        </div>
                                        <div class="radio-item">
                                            <input type="radio" name="ext08" id="ext08否" value="否"
                                                onchange="changeExt08()" checked>
                                            <label for="ext08">否</label>
                                        </div>
                                    </div>
                                </div>
                            </li>

                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label">添加图片</div>
                                    <div class="aui-list-item-input">
                                        <div class="aui-content" style="background-color: #ffffff">
                                            <ul class="aui-list-view aui-grid-view" id="imgslist">
                                                <li class="aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5"
                                                    id="addpic" onclick="imgClick()">
                                                    <img class="aui-img-object" style="padding: 5px;"
                                                        src="../image/photo-add.png">
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </li>

                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修描述</div>
                                </div>
                            </li>
                            <div>
                                <textarea style="width:90%; margin-left: 15px; background-color: #f0f0f0;"
                                    id="repairDescription" placeholder="请填写维修描述"></textarea>
                            </div>

                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修人</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="ydPerson" value="" />
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修班组</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="ydPersonTeam" value="" />
                                    </div>
                                </div>
                            </li>

                        </ul>
                    </div>
                </div>
            </div>
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                        <ul class="aui-list aui-form-list" style="content: none;">
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label ui-selectee" style="width: 45%;">设备部位</div>
                                    <div class="aui-list-item-input ui-selectee"> <input class="form-control"
                                            type="text" id="ext10">
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">故障原因</div>
                                    <div class="aui-list-item-input">
                                        <select id="causeAnalysis" placeholder="请选择">
                                        </select>
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修级别</div>
                                    <div class="aui-list-item-input">
                                        <select id="ext12" placeholder="请选择">
                                        </select>
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label" style="width: 45%;">维修类别</div>
                                    <div class="aui-list-item-input">
                                        <select id="ext23" placeholder="请选择">
                                        </select>
                                    </div>
                                </div>
                            </li>
                            <li class="aui-list-item">
                                <div class="aui-list-item-inner">
                                    <div class="aui-list-item-label">维修单号</div>
                                    <div class="aui-list-item-input">
                                        <input type="text" readonly id="ext03" value="" />
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!-- 更换备件 -->
        <div class="aui-hide" id="tab1-con3">
            <div class="aui-btn aui-btn-block" style="background-color:#ffffff;" onclick="goSelectMrl()">
                <i class="aui-iconfont aui-icon-add aui-text-epblue" style="font-size: 0.7rem;height: 100px;"
                    id="addSelectMrlBtn">备用件领用</i>

            </div>
            <div class="aui-content" id="divHtml" style="margin-top: 10px;"></div>
        </div>
        <!-- 处理过程 -->
        <div class="aui-hide" id="tab1-con4">
            <div id="timeLineContainer" class="time-line-container">
                <!-- 时间线内容将通过 JavaScript renderTimeLine 动态生成 -->
            </div>
        </div>



    </div>
    <footer class="aui-bar aui-bar-tab ui-selectee" style="color: #f5f5f5;">
        <div id="footer" class="aui-bar aui-bar-btn aui-bar-btn-full ui-selectee"
            style="min-height: 2.8rem;font-size: 1.0rem;">
            <div class="aui-bar-btn-item ui-selectee" style="border-color: #f5f5f5;background-color: #49A0E4;"
                onclick="saveSubmit('1')">保存信息</div>
            <div class="aui-bar-btn-item ui-selectee" style="border-color: #f5f5f5;background-color: #49A0E4;"
                onclick="saveSubmit('2')">结束维修</div>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script>
    var Bjlist = [];
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
    apiready = function () {
        if ('readOnly' == api.pageParam.readOnly) {
            document.getElementById("footer").style.display = "none";


            document.getElementById("beginDate").disabled = true;

            document.getElementById("endDate").disabled = true;

            document.getElementById("ext04hour").disabled = true;

            document.getElementById("ext04min").disabled = true;


            const radioButtons = document.getElementsByName("ext15");
            radioButtons.forEach(radio => {
                radio.disabled = true;
            });

            document.getElementById("ext17hour").disabled = true;

            document.getElementById("ext17min").disabled = true;

            document.getElementById("ext28").disabled = true;

            document.getElementById("faultClass").disabled = true;


            const radioButtonsExt08 = document.getElementsByName("ext08");
            radioButtonsExt08.forEach(radio => {
                radio.disabled = true;
            });


            const addPicElement = document.getElementById("addpic");

            addPicElement.onclick = null;

            addPicElement.style.opacity = "0.5";
            addPicElement.style.pointerEvents = "none";

            document.getElementById("repairDescription").disabled = true;

            document.getElementById("ext10").disabled = true;
            document.getElementById("causeAnalysis").disabled = true;
            document.getElementById("ext12").disabled = true;
            document.getElementById("ext23").disabled = true;

            const addMrlBtn = document.getElementById("addSelectMrlBtn").parentElement;

            addMrlBtn.onclick = null;

            addMrlBtn.style.opacity = "0.5";
            addMrlBtn.style.pointerEvents = "none";
            addMrlBtn.style.cursor = "not-allowed";


            const divHtml = document.getElementById("divHtml");
            divHtml.style.pointerEvents = "none";
            divHtml.style.opacity = "0.7";  

            const interactiveElements = divHtml.querySelectorAll('input, select, button, textarea, [onclick]');
            interactiveElements.forEach(el => {
                if (el.tagName === 'INPUT' || el.tagName === 'SELECT' || el.tagName === 'TEXTAREA' || el.tagName === 'BUTTON') {
                    el.disabled = true;
                }
                if (el.hasAttribute('onclick')) {
                    el.removeAttribute('onclick');
                }
            });
        }

        //设备信息
        getEmequipmentfaultDataInfo(api.pageParam.sysid, "1"); //获取设备故障tab页信息


        api.parseTapmode();
        // 引入多选模块
        uiMediaScanner = api.require('UIMediaScanner');
        // 引入过滤压缩模块
        imageFilter = api.require("imageFilter");
        // 引入图片浏览模块
        imageBrowser = api.require('imageBrowser');
        //监听子页面发送的“备件选中”事件
        // api.addEventListener({
        //     name: 'sparePartsSelected' // 必须与子页面的事件名一致
        // }, function (ret) {
        //     if (ret && ret.value && ret.value.selectedItems) {
        //         const selectedItems = JSON.parse(ret.value.selectedItems);
        //         console.log("从备件页带回的数据：", JSON.stringify(selectedItems));
        //         // 遍历selectedItems
        //         selectedItems.forEach(item => {
        //             // 检查Bjlist中是否存在相同code的元素
        //             let existingItem = Bjlist.find(bjItem => bjItem.code === item.code);
        //             if (existingItem) {
        //                 // 如果存在，将quantity相加
        //                 existingItem.quantity += item.quantity;
        //             } else {
        //                 // 如果不存在，将selectedItems中的元素添加到Bjlist中
        //                 Bjlist.push(item);
        //             }
        //         });
        //         creatHtml(Bjlist)
        //     }
        // });

        //获得处理过程
        renderTimeLine()

        //获得备件列表
        getFaultBj()

        //开始时间选择
        // new Jdate({
        //     el: '#beginDate',
        //     format: 'YYYY-MM-DD hh:mm:ss',
        //     beginYear: 2000,
        //     endYear: 2100
        // });
        // //结束时间选择
        // new Jdate({
        //     el: '#endDate',
        //     format: 'YYYY-MM-DD hh:mm:ss',
        //     beginYear: 2000,
        //     endYear: 2100,
        // });

        //查询班组下拉框
        doSearchTeamGid();

        //查询维修状态下拉框
        doSearchEXT28List()

        //查询故障类别下拉框
        doSearchFaultClassList()

        //查询故障原因下拉框
        doSearchCauseAnalysisList()

        //查询维修级别下拉框
        doSearchEXT12List()

        //查询维修类别下拉框
        doSearchEXT23List()

        //图片
        getEmequipmentfaultFile(api.pageParam.sysid)
    }

    //监听子页面发送的“备件选中”事件
    function sparePartsSelected(selectedItems) {
        if (selectedItems) {
            // const selectedItems = JSON.parse(ret.value.selectedItems);
           // console.log("从备件页带回的数据：", JSON.stringify(selectedItems));
            // 遍历selectedItems
            selectedItems.forEach(item => {
                // 检查Bjlist中是否存在相同code的元素
                let existingItem = Bjlist.find(bjItem => bjItem.code === item.code);
                if (existingItem) {
                    // 如果存在，将quantity相加
                    existingItem.quantity += item.quantity;
                } else {
                    // 如果不存在，将selectedItems中的元素添加到Bjlist中
                    Bjlist.push(item);
                }
            });
            creatHtml(Bjlist)
        }
    }

    var tab = new auiTab({
        element: document.getElementById("tab"),

    }, function (ret) {
        if (ret) {
            //定义获取对象的所有兄弟节点的函数，
            function siblings(elm) {
                var a = [];
                var p = elm.parentNode.children;
                for (var i = 0; i < p.length; i++) {
                    if (p[i] !== elm) a.push(p[i]);
                }
                return a;
            }
            var index = ret.index;
            var activeC = document.getElementById("tab1-con" + index);
            activeC.className = "";
            for (var i = 0; i < siblings(activeC).length; i++) {
                siblings(activeC)[i].className = "aui-hide";
            }
        }
    });



    // 切换标签选中状态
    function setActiveTab(index) {
        var tabItems = document.querySelectorAll('#tab .aui-tab-item');
        // 移除所有选中状态
        tabItems.forEach(item => item.classList.remove('aui-active'));
        // 设置目标标签为选中
        if (tabItems[index - 1]) {
            tabItems[index - 1].classList.add('aui-active');
        }
        // 切换对应内容
        function siblings(elm) {
            var a = [];
            var p = elm.parentNode.children;
            for (var i = 0; i < p.length; i++) {
                if (p[i] !== elm) a.push(p[i]);
            }
            return a;
        }
        var activeC = document.getElementById("tab1-con" + index);
        activeC.className = "";
        for (var i = 0; i < siblings(activeC).length; i++) {
            siblings(activeC)[i].className = "aui-hide";
        }
    }

    //增加备件
    function goSelectMrl() {
        api.openWin({
            name: 'emequipmentfaltSelectSpareParts',
            url: 'emequipmentfaltSelectSpareParts.html',
            pageParam: {
                name: "emequipmentfaltRepaire",
                sysid: api.pageParam.sysid,
                equipCode: $("#equipCode").val()
            }
        });
    }

    // 生成备件列表HTML（所有标识统一用sysid）
    function creatHtml(list) {
        var str = '';
        const divHtml = document.getElementById("divHtml");
        divHtml.innerHTML = ""; // 清空旧内容

        for (let i = 0; i < list.length; i++) {
            const item = list[i];
            // 跳过无sysid的项（避免异常）
            if (!item.sysid) continue;

            str += `
                <div style='margin-top: 10px; height: 120px;color: grey;background-color:white;border-radius:8px;box-shadow: 0 2px 4px rgba(0,0,0,0.1);overflow:hidden;'>
                    <!-- 左侧图片区域 -->
                    <div style='width: 30%;height: 100%;float: left;margin-right: 1%'>
                        ${item.ext12 ?
                    `<img src='${item.ext12}' style='width: 100%; height: 100%;object-fit: cover;'>`
                    :
                    `<div class='aui-text-center' style='color: #fff;font-size: 15px;height: 100%;padding-top: 45%;background-color:#ccc;'>
                                    <span>未上传图片</span>
                                </div>`
                }
                    </div>

                    <!-- 右侧信息区域 -->
                    <div style='width: 67%;height: 100%;float: left;font-size:12px;text-align: left;padding-left: 2%;box-sizing: border-box;'>
                        <!-- 名称 + 复选框（复选框用data-sysid标识） -->
                        <div style='font-weight: bold;font-size:14px;color: black;margin-top:10px;display: flex;justify-content: space-between;align-items: center;'>
                            <span>${item.name || '未命名设备'}</span>
                        </div>

                        <!-- 备件信息（保留原code显示，不影响唯一值） -->
                        <div>备件编码：${item.code || ''}</div>
                        <div>规格型号：${item.spec || ''}</div>
                        <div>备件类型：${item.type || ''}</div>
                        <div>备件数量：
                        <!-- 减少数量按钮 -->
                            <span 
                                style="display: inline-block; width: 20px; height: 20px; text-align: center; line-height: 20px; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; margin-right: 5px;"
                                onclick="decreaseQuantity('${item.code || item.name}')">
                                -
                            </span>
                            ${item.quantity || ''}
                            <!-- 增加数量按钮 -->
                            <span 
                                style="display: inline-block; width: 20px; height: 20px; text-align: center; line-height: 20px; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; margin-left: 5px;"
                                onclick="increaseQuantity('${item.code || item.name}')">
                                +
                            </span>
                        <!-- 删除按钮：调用独立的deleteBjItem方法，传入当前item的唯一标识（如code） -->

                        <span 
                            style="color: #ff4d4f; cursor: pointer; font-size: 12px; text-decoration: underline; display: inline-block;"
                            onclick="deleteBjItem('${item.code || item.name}')">
                            删除
                        </span>
                    </div>
                    </div>
                </div>
            `;
        }



        divHtml.innerHTML = str;
    }

    // 增加数量
    function increaseQuantity(uniqueKey) {

        // 2. 根据唯一标识（code/name）找到元素索引
        // （优先用code匹配，无code则用name，确保能定位到唯一元素）
        const targetIndex = Bjlist.findIndex(item => {
            return item.code === uniqueKey || item.name === uniqueKey;
        });

        // 3. 找到元素则删除，并重新渲染页面
        if (targetIndex !== -1) {
            Bjlist[targetIndex].quantity = Bjlist[targetIndex].quantity + 1; // 从数组中删除对应元素
            creatHtml(Bjlist); // 调用你的渲染方法，刷新页面列表
        } else {
            console.warn('未找到要删除的元素，唯一标识：', uniqueKey); // 可选：调试用
        }
    }

    // 减少数量（确保不小于0）
    function decreaseQuantity(uniqueKey) {

        // 2. 根据唯一标识（code/name）找到元素索引
        // （优先用code匹配，无code则用name，确保能定位到唯一元素）
        const targetIndex = Bjlist.findIndex(item => {
            return item.code === uniqueKey || item.name === uniqueKey;
        });

        // 3. 找到元素则删除，并重新渲染页面
        if (targetIndex !== -1) {
            Bjlist[targetIndex].quantity = Bjlist[targetIndex].quantity - 1; // 从数组中删除对应元素
            creatHtml(Bjlist); // 调用你的渲染方法，刷新页面列表
        } else {
            console.warn('未找到要删除的元素，唯一标识：', uniqueKey); // 可选：调试用
        }
    }

    // 全局删除方法：根据item的唯一标识删除Bjlist中的对应元素
    function deleteBjItem(uniqueKey) {


        // 2. 根据唯一标识（code/name）找到元素索引
        // （优先用code匹配，无code则用name，确保能定位到唯一元素）
        const targetIndex = Bjlist.findIndex(item => {
            return item.code === uniqueKey || item.name === uniqueKey;
        });

        // 3. 找到元素则删除，并重新渲染页面
        if (targetIndex !== -1) {
            Bjlist.splice(targetIndex, 1); // 从数组中删除对应元素
            creatHtml(Bjlist); // 调用你的渲染方法，刷新页面列表
        } else {
            console.warn('未找到要删除的元素，唯一标识：', uniqueKey); // 可选：调试用
        }
    }




    //是否停机
    function changeExt15() {
        var flag = $('input[name="ext15"]:checked').val()
        if ('否' == flag) {
            $("#ext17hour").val('');
            $("#ext17min").val('');
        }
    }

    //是否更换配件
    function changeExt08() {
        var flag = $('input[name="ext08"]:checked').val()
        var selectedMrl = document.getElementById("selectedMrl");
        var tabItems = document.querySelectorAll('#tab .aui-tab-item');

        // 找到"更换备件"标签的索引位置
        var targetIndex = Array.from(tabItems).findIndex(item => item.id === 'selectedMrl');

        if ('是' == flag) {
            // 显示标签
            selectedMrl.style.display = "block";
            // 延迟执行跳转（确保组件已初始化完成）
            setActiveTab(3);
        } else {
            selectedMrl.style.display = "none";
        }
    }

    //获取计划关联人员信息
    function getEmPlanEmpDataList(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getemPlanEmpDataList";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-title ui-selectee' name='empName' title='" + list[i].empName + "'>" + list[i].empName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' name='empCode'>" + list[i].empCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].groupName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='actualtime' οnkeyup='value=value.replace(/[^\d]/g,'')' ";
                        html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' value='" + list[i].actualtime + "'></div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee'></div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee delEmp' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    //console.log(html);
                    //console.log($api.byId("tbodyHtml"));
                    $api.html($api.byId("tbodyHtml"), html);
                    //console.log($("#tbodyHtml").html());

                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //获取计划关联备件信息
    function getEmPlanBJDataList(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmPlanBJDataList";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-title ui-selectee' name='mtlName'>" + list[i].mtlName + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>备件编码</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' name='mtlCode'>" + list[i].mtlCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'><input type='number'  name='qty' οnkeyup='value=value.replace(/[^d]/g,' ')' ";
                        html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' ";
                        html += "value='" + list[i].qty + "'></div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'>";
                        html += "<div class='aui-list-item-label ui-selectee'></div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee delMrl' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    $api.html($api.byId("tbodyMrlHtml"), html);

                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyMrlHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //获取信息
    function getEmequipmentfaultDataInfo(sysid, tab) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEquipmentFaultList";
        var data = {
            values: {
                sysid: sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var entity = list[0];
                    if (tab == "1") { //设备故障123
                        $("#equipCode").val(entity.equipCode);
                        $("#equipName").val(entity.equipName);
                        $("#equipModel").val(entity.equipModel);
                        $("#equipmentType").val(entity.equipmentType);
                        $("#ext09").val(entity.ext09);
                        $("#faultOrderNo").val(entity.faultOrderNo);
                        $("#description").val(entity.description);

                        $("#ext06").val(entity.ext06);
                        $("#contact").val(entity.contact);
                        $("#faultdate1").val(entity.ext30);
                        $("#faultdate2").val(entity.faultdate);
                        $("#faultlocation").val(entity.ext09);
                        $("#ydPerson").val(entity.ydPerson);
                        $("#ydPersonTeam").val(entity.ydPersonTeam);
                        $("#ext16").val(entity.ext16);

                        //开始时间
                        if (entity.beginDate != null && entity.beginDate != undefined && entity.beginDate != '') {
                            const beginDate = entity.beginDate.replace(' ', 'T').slice(0, 16);
                            $("#beginDate").val(beginDate);
                        }
                        //结束时间
                        if (entity.endDate != null && entity.endDate != undefined && entity.endDate != '') {
                            const endDate = entity.endDate.replace(' ', 'T').slice(0, 16);
                            $("#endDate").val(endDate);
                        }
                        var ext04 = convertToHoursAndMinutes(entity.ext04)
                        $("#ext04hour").val(ext04.hour);
                        $("#ext04min").val(ext04.min);
                        $("#ext15").val(entity.ext15);
                        var ext17 = convertToHoursAndMinutes(entity.ext17)
                        $("#ext17hour").val(ext17.hour);
                        $("#ext17min").val(ext17.min);
                        $("#ext28").find("option:contains('" + entity.ext28 + "')").attr("selected", true);
                        $("#faultClass").find("option:contains('" + entity.faultClass + "')").attr("selected", true);
                        $('input[name="ext15"][value="' + entity.ext15 + '"]').prop('checked', true);
                        $('input[name="ext08"][value="' + entity.ext08 + '"]').prop('checked', true);
                        if ('是' == entity.ext08) {
                            document.getElementById("selectedMrl").style.display = "block";
                        }
                        $("#repairDescription").val(entity.repairDescription);
                        $("#ext10").val(entity.ext10);
                        $("#causeAnalysis").find("option:contains('" + entity.causeAnalysis + "')").attr("selected", true);
                        $("#ext12").find("option:contains('" + entity.ext12 + "')").attr("selected", true);
                        $("#ext23").find("option:contains('" + entity.ext23 + "')").attr("selected", true);
                        $("#ext03").find("option:contains('" + entity.ext03 + "')").attr("selected", true);
                        $("#ydPerson").val(entity.ydPerson);
                        $("#ydPersonTeam").val(entity.ydPersonTeam);

                    } else if (tab == "2") {


                    }

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选择维修人员
    function goSelectEmp() {
        api.openWin({
            name: 'mdEmployeeSelect',
            url: 'mdEmployeeSelect.html',
            pageParam: {
                name: "emequipmentfaltRepaire"
            }
        });
    }

    //人员选择后回调函数
    function setEmployeeList(dataList) {
        var list = dataList; //JSON.parse(dataList);
        var html = "";
        for (i in list) {
            html += "<li class='sortable ui-selectee ui-sortable' name='litr'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-title ui-selectee' name='empName'>" + list[i].name + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>人员编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee' name='empCode'>" + list[i].code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>班组</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].teamName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>维修工时(分)</div>";
            html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='actualtime'  οnkeyup='value=value.replace(/[^\d]/g,'')' ";
            html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' value='" + 0 + "'></div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee'></div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee delEmp' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
            html += "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.append($api.byId("tbodyHtml"), html);

    }

    //删除人员
    $(document).on('click', '.delEmp', function () {
        var othis = this;
        api.confirm({
            title: '删除',
            msg: '确认删除该人员信息？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                $(othis).parent().parent().parent().parent().parent().parent().remove();
            } else { }
        });


    })


    //备件选择后回调函数
    function setMrlList(dataList) {
        var list = dataList; //JSON.parse(dataList);
        var html = "";
        for (i in list) {
            html += "<li class='sortable ui-selectee ui-sortable parent' name='litr'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item ui-selectee' style='border: 1px solid #aba9a9;list-style-position: inside;margin-bottom:-1px;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-title ui-selectee' name='mtlName'>" + list[i].name + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>备件编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee'name='mtlCode'>" + list[i].code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量</div>";
            html += "<div class='aui-list-item-inner ui-selectee'><input type='number' name='qty'  οnkeyup='value=value.replace(/[^d]/g,' ')' ";
            html += "style='border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: solid;border-bottom-width: 0.5px;width: 50%;' ";
            html += "value='0'></div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee'>";
            html += "<div class='aui-list-item-label ui-selectee'></div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee delMrl' style='background:#d41a10;color:#f5f5f5;'>删除</div>";
            html += "</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";

        }
        $api.append($api.byId("tbodyMrlHtml"), html);

    }

    //删除备件
    $(document).on('click', '.delMrl', function () {
        var othis = this;
        api.confirm({
            title: '删除',
            msg: '确认删除该备件信息？',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                $(othis).parent().parent().parent().parent().parent().parent().remove();
            } else { }
        });


    })

    //维修类别下拉框
    function doSearchEXT23List() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                code: "EQUIP_REPAIR_TYPE",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("ext23"), html);
            }
        });
    }

    //维修级别下拉框
    function doSearchEXT12List() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                code: "EQUIP_REPAIR_LEVEL",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("ext12"), html);
            }
        });
    }

    //故障原因下拉框
    function doSearchCauseAnalysisList() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                code: "EQUIP_FAULT_STATUS_CAUSE",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("causeAnalysis"), html);
            }
        });
    }


    //故障类别下拉框
    function doSearchFaultClassList() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                code: "EQUIP_FAULT_CLASS",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("faultClass"), html);
            }
        });
    }

    //维修状态下拉框
    function doSearchEXT28List() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                code: "EQUIP_REPAIR_STATUS",
                un, un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("ext28"), html);
            }
        });
    }

    //班组下拉框
    function doSearchTeamGid() {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                tablename: "md_labour_group",
                column_name: "group_name",
                column_value: "sysid",
                condition: " is_del=0 ",
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("teamGid"), html);
            }
            //查询状态下拉框
            doSearchMdparaconfig("emEquipmentFaultStatus", "status");

        });
    }
    //业务参数下拉框
    function doSearchMdparaconfig(paracls, idH) {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdparaconfig";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                paracls: paracls
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId(idH), html);
            }
            //查询故障类别下拉框
            doSearchMdparaconfig2("emEquipmentFaultClass", "faultClass");

        });
    }
    //业务参数下拉框
    function doSearchMdparaconfig2(paracls, idH) {
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdparaconfig";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                paracls: paracls
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId(idH), html);
            }
        });
    }


    // 转换Date对象为datetime-local所需的格式 (YYYY-MM-DDThh:mm)
    function formatDateTime(inputId) {
        const input = document.getElementById(inputId);
        if (!input.value) return "";

        // 将输入值转换为Date对象
        const date = new Date(input.value);

        // 获取各时间部分并补零
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0'); // 秒数默认取当前

        // 拼接成目标格式
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    }

    document.getElementById('endDate').addEventListener('change', calculateTimeDifference);

    //计算维修用时
    function calculateTimeDifference() {
        const beginDateValue = document.getElementById('beginDate').value;
        const endDateValue = document.getElementById('endDate').value;


        if (!beginDateValue || !endDateValue) {
            document.getElementById('ext04').value = '';
            return;
        }

        const beginDate = new Date(beginDateValue);
        const endDate = new Date(endDateValue);

        const timeDifference = (endDate - beginDate) / (1000 * 60);

        if (timeDifference >= 0) {
            var ext04 = convertToHoursAndMinutes(timeDifference)
            $("#ext04hour").val(ext04.hour);
            $("#ext04min").val(ext04.min);
        }

    }


    //提交
    function saveSubmit(value) {
        //设备故障主键
        var sysid = api.pageParam.sysid;
        //开始时间
        var beginDate = formatDateTime("beginDate");//$("#beginDate").val();
        //结束时间
        var endDate = formatDateTime("endDate");//$("#endDate").val();
        //维修用时
        var ext04hour = $("#ext04hour").val();
        var ext04min = $("#ext04min").val();
        if (ext04hour === null || ext04hour.trim() === "") {
            ext04hour = "0";  // 如果为空，设置默认值为 0
        }
        if (ext04min === null || ext04min.trim() === "") {
            ext04min = "0";  // 如果为空，设置默认值为 0
        }
        var ext04 = parseInt(ext04hour, 10) * 60 + parseInt(ext04min, 10);
        //是否停机
        var ext15 = $('input[name="ext15"]:checked').val()
        //停机时长
        var ext17hour = $("#ext17hour").val();
        var ext17min = $("#ext17min").val();
        if (ext17hour === null || ext17hour.trim() === "") {
            ext17hour = "0";  // 如果为空，设置默认值为 0
        }
        if (ext17min === null || ext17min.trim() === "") {
            ext17min = "0";  // 如果为空，设置默认值为 0
        }
        var hourAsNumber = parseInt(ext17hour, 10);  // 将小时转换为整数
        var minAsNumber = parseInt(ext17min, 10);    // 将分钟转换为整数
        var ext17 = hourAsNumber * 60 + minAsNumber;
        //维修状态
        var ext28 = $("#ext28").val();
        //故障类别
        var faultClass = $("#faultClass").val();
        //是否更换配件
        var ext08 = $('input[name="ext08"]:checked').val()
        //维修描述
        var repairDescription = $("#repairDescription").val();
        //设备部位
        var ext10 = $("#ext10").val();
        //故障原因
        var causeAnalysis = $("#causeAnalysis").val();
        //维修级别
        var ext12 = $("#ext12").val();
        //维修类别
        var ext23 = $("#ext23").val();
        //维修单号
        var ext03 = $("#ext03").val();
        var ydPersonTeam = $("#ydPersonTeam").val();
        //计划关联人员
        var listEmp = [];
        // $("ul[id=tbodyHtml] li[name=litr]").each(function (index) {
        //     var empName = document.getElementsByName("empName")[index].innerText;
        //     var empCode = document.getElementsByName("empCode")[index].innerText;
        //     var actualtime = document.getElementsByName("actualtime")[index].value;
        //     var mo = {
        //         planGid: sysid,
        //         planClass: '2', //故障维修
        //         empName: empName,
        //         empCode: empCode,
        //         actualtime: actualtime
        //     }
        //     //只有实际工时大于0 才提交
        //     if (parseFloat(actualtime) > 0) {
        //         listEmp.push(mo);
        //     }

        // })
        //计划关联备件
        var listBj = Bjlist;
        // $("ul[id=tbodyMrlHtml] li[name=litr]").each(function (index) {
        //     var mtlName = document.getElementsByName("mtlName")[index].innerText;
        //     var mtlCode = document.getElementsByName("mtlCode")[index].innerText;
        //     var qty = document.getElementsByName("qty")[index].value;
        //     var mo = {
        //         planGid: sysid,
        //         planClass: '2', //故障维修
        //         mtlName: mtlName,
        //         mtlCode: mtlCode,
        //         qty: qty
        //     }
        //     //只有数量大于0 才提交
        //     if (parseFloat(qty) > 0) {
        //         listBj.push(mo);
        //     }

        // })

        // 获取 id 为 "addpic" 的容器内所有 img
        var content = document.getElementById('imgslist');
        var imgs = content.getElementsByTagName('img');
        var names = [];
        // console.log("imgsimgsimgsimgs666:" + JSON.stringify(content.innerHTML));
        // console.log("imgsimgsimgsimgs:" + JSON.stringify(content));
        // console.log("imgsimgsimgsimgs222:" + JSON.stringify(imgs));
        for (var i = 0; i < imgs.length; i++) {
            var img = imgs[i];
            if (img.hasAttribute('id')) {
                //判断图片是否有id属性，只有之前保存过的图片才有id 即文件名称
                names[i] = img.id;

            } else {
                var srcStr = img.getAttribute('src');
                var arrs = srcStr.split('\/');
                var nameStr = arrs[arrs.length - 1];
                if ("photo-add.png" != nameStr) {
                    names[i] = nameStr;
                }
            }

        }
        var picNames = JSON.parse(JSON.stringify(names));

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un'); //登录用户
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/emRepaireSave";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un, //登录用户
                sysid: sysid, //设备故障主键
                beginDate: beginDate, //开始时间
                endDate: endDate, //结束时间
                ext15: ext15, //是否停机
                ext17: ext17, //停机时长
                ext28: ext28, //维修状态
                faultClass: faultClass, //故障类别
                ext08: ext08, //是否更换配件
                repairDescription: repairDescription, //维修描述
                ext10: ext10, //设备部位
                causeAnalysis: causeAnalysis, //故障原因
                ext12: ext12, //维修级别
                ext04: ext04, //维修用时
                ext23: ext23, //维修类别
                ext03: ext03, //维修单号
                ydPersonTeam: ydPersonTeam,//维修班组
                picNames: picNames,//保养图片
                listBj: JSON.stringify(listBj)
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    if (value == '2') {
                        endSubmit()
                    }

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }


    //提交
    function endSubmit() {
        //设备故障主键
        var sysid = api.pageParam.sysid;

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un'); //登录用户
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/emRepaireOver";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un, //登录用户
                sysid: sysid, //设备故障主键
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    api.closeWin({
                        name: 'emequipmentfaultRepaireListDetail',
                        delay: 100 // 延迟关闭，确保数据发送完成
                    });
                    api.closeWin({
                        name: 'emequipmentfaultRepaireingList',
                        delay: 100 // 延迟关闭，确保数据发送完成
                    });
                    // api.openWin({
                    //     name: 'emequipmentfaultRepaireList',
                    //     url: 'emequipmentfaultRepaireList' + '.html',
                    //     reload: true,
                    //     delay: 300 // 延迟关闭，确保数据发送完成
                    // });
                    api.closeWin({
                        name: 'emequipmentfaultRepaireList',
                        url: 'emequipmentfaultRepaireList' + '.html',
                        reload: true,
                        delay: 300 // 延迟关闭，确保数据发送完成
                    });
                    api.closeWin({
                        name: 'emequipmentfaltRepaire',
                        delay: 400 // 延迟关闭，确保数据发送完成
                    });
                    api.openWin({
                        name: 'emequipmentfaltToAcceptOrders',
                        url: 'emequipmentfaltToAcceptOrders' + '.html',
                        reload: true,
                        delay: 300 // 延迟关闭，确保数据发送完成
                    });

                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    // 模拟假数据
    function getFakeTimeLineData() {
        return [
            {
                person: "林工",
                statusType: "报修",
                statusDesc: "故障报修",
                time: "2025-07-17 09:50:27",
                isActive: false
            },
            {
                person: "林工",
                statusType: "接单",
                statusDesc: "接单，林工",
                time: "2025-07-17 09:54:27",
                isActive: false
            },
            {
                person: "谷工",
                statusType: "维修",
                statusDesc: "维修派工，维修人员：谷工",
                time: "2025-07-17 12:50:27",
                isActive: false
            },
            {
                person: "谷工",
                statusType: "维修",
                statusDesc: "开始维修",
                time: "2025-07-17 12:52:27",
                isActive: false
            },

            {
                person: "谷工",
                statusType: "维修",
                statusDesc: "执行维修",
                time: "2025-07-17 12:54:27",
                isActive: true
            }
        ];
    }

    // 获得维修备件
    function getFaultBj() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getFaultBj";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                sysid: api.pageParam.sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                list.forEach(item => {
                    item.code = item.mtlCode
                    item.name = item.mtlName
                    item.quantity = item.qty
                });
                Bjlist = list
                creatHtml(Bjlist)
            }
        });
    }

    // 渲染时间线
    function renderTimeLine() {

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getFaultProcess";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                sysid: api.pageParam.sysid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            async: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);

                let html = '';
                list.forEach(item => {
                    html += `
        <div class="time-line-item">
            <div class="time-line-person">${item.personName}</div>
            <div class="time-line-dot ${item.isActive ? 'active' : ''}"></div>
            <div class="time-line-info">
                <div class="time-line-status">
                    <div class="time-line-status-type">${item.operationType}</div>
                    <div class="time-line-status-desc">${item.operationContent}</div>
                </div>
                <div class="time-line-time">${item.createDate}</div>
            </div>
        </div>
        `;
                });
                $api.html($api.byId("timeLineContainer"), html);

            }
        });
    }

    //时间转换
    function convertToHoursAndMinutes(totalMinutes) {
        const hours = Math.floor(totalMinutes / 60);
        const minutes = totalMinutes % 60;
        return {
            hour: hours,
            min: minutes,
        };
    }


    //图片上传
    function imgClick() {
        // 获取图片宽高
        var normalW = $("#addpic img").width();
        api.actionSheet({
            title: '选择图片来源',
            buttons: ['照相机', '浏览相册']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            switch (index) {
                // 拍照
                case 1:
                    // 打开拍照
                    api.getPicture({
                        sourceType: "camera",
                        encodingType: "jpg",
                        destinationType: "url",
                        mediaValue: "pic",
                        quality: 50,
                        saveToPhotoAlbum: true
                    }, function (ret, err) {
                        if (ret && ret.data) {
                            // 拍照返回的本地路径
                            var returnUrl = ret.data;
                            // 图片压缩
                            imgCompress(returnUrl, 0.5, 0.5, getExt(returnUrl), function (compressImg) {
                                var showImgHtml = "<li id='test' class='aui-list-view-cell aui-img aui-col-xs-4  aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;' onclick='lookImg(\"" + compressImg + "\")'><img class='aui-img-object' src='" + compressImg +
                                    "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                                // 追加图片
                                $("#addpic").before(showImgHtml);
                                // ########################################  绑定长按事件 ########################
                                addPress($("#imgslist img[src='" + compressImg + "']").parent("li"));

                                //上传图片
                                uploadFile(compressImg);
                            });
                        } else {
                            api.toast({
                                msg: '没有选择，或者选择出错'
                            });
                        }
                    });
                    break;
                // 打开图片选择器
                case 2:
                    uiMediaScanner.open({
                        type: 'picture',
                        column: 4,
                        classify: true,
                        max: 5,
                        sort: {
                            key: 'time',
                            order: 'desc'
                        },
                        texts: {
                            stateText: '已选*项',
                            cancelText: '取消',
                            finishText: '完成'
                        },
                        styles: {
                            bg: '#fff',
                            mark: {
                                icon: '',
                                position: 'bottom_left',
                                size: 20
                            },
                            nav: {
                                bg: '#b23e4b',
                                stateColor: '#fff',
                                stateSize: 18,
                                cancelBg: 'rgba(0,0,0,0)',
                                cancelColor: '#fff',
                                cancelSize: 18,
                                finishBg: 'rgba(0,0,0,0)',
                                finishColor: '#fff',
                                finishSize: 18
                            }
                        }
                    }, function (ret) {
                        if (ret) {
                            if (ret.list) {
                                for (var i = 0; i < ret.list.length; i++) {
                                    console.log(i)
                                    var selectImg = ret.list[i];
                                    // 获取图片的路径
                                    var selectimgPath = selectImg.path;
                                    var selectimgThumbPath = selectImg.thumbPath;
                                    // 图片压缩
                                    imgCompress(selectimgPath, 0.5, 0.5, selectImg.suffix, function (compressImg) {
                                        var showImgHtml = "<li id='test' class='aui-list-view-cell aui-img aui-col-xs-4 aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;'  onclick='lookImg(\"" + compressImg + "\")'><img class='aui-img-object' src='" + compressImg +
                                            "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                                        // 追加图片
                                        $("#addpic").before(showImgHtml);
                                        // ########################################  绑定长按事件 ########################
                                        addPress($("#imgslist img[src='" + compressImg + "']").parent("li"));

                                        // ################### 上传图片 #########################
                                        uploadFile(compressImg);
                                    });
                                }
                            }
                        }
                    });
                    break;
            }
        });
    }

    // 图片压缩
    // imgsrc：源图片的路径
    // quality：图片压缩质量，一般建议0.5
    // scale：图片压缩比例，也是建议0.5
    // ext：源图片拓展名
    // callback：转换成功之后回调函数
    function imgCompress(imgsrc, quality, scale, ext, callback) {
        // 压缩文件的保存目录
        var savePath = api.cacheDir + "/" + getNowFormatDate() + "/";
        // 压缩文件生成的随机文件名称
        var savename = NewGuid() + "." + ext;
        imageFilter.compress({
            img: imgsrc,
            quality: quality,
            scale: quality,
            save: {
                album: false,
                imgPath: savePath,
                imgName: savename
            }
        }, function (ret, err) {
            if (ret) {
                callback(savePath + savename);
            } else {
                console.log((JSON.stringify(err)));
            }
        });
    }

    // 打开图片浏览
    // imgs：需要预览的图片集合
    function openImageBrowser(imgs) {
        imageBrowser.openImages({
            imageUrls: imgs,
            showList: false,
            activeIndex: 0
        });
    }

    // 获取当前的时间，拼接成2015-11-09这样的格式，主要用于对图片进行时间分类
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate
        return currentdate;
    }

    // 获取文件拓展名
    function getExt(fileName) {
        return fileName.substring(fileName.lastIndexOf('.') + 1);
    }

    // 生成guid,主要用于生成随机文件名
    function NewGuid() {
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }

        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }

    // 添加长按方法
    function addPress(obj, index) {
        // 获取目前长按的对象
        var hammertime = new Hammer(obj[0]);
        // 绑定长按对象
        hammertime.on("press", function (e) {
            api.confirm({
                title: '温馨提示',
                msg: '您确定要删除该图片吗？',
                buttons: ['确定', '取消']
            }, function (ret, err) {
                if (ret.buttonIndex == 1) {
                    // 移除自己
                    $(obj).remove();
                    api.toast({
                        msg: '删除成功！'
                    });
                }
            });
        });
    }
    //获取信息
    function getEmequipmentfaultFile(sysid) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEmequipmentfaultFileList";
        var data = {
            values: {
                sysid: sysid,
                status: '0',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list)
                    var normalW = $("#addpic img").width();
                    if (list && list.length > 0) {
                        // var str = '';
                        for (var i = 0; i < list.length; i++) {
                            var imgInfo = list[i]
                            var imgUrl = imgInfo.filePath;
                            var showImgHtml = "<li id='test' class='aui-list-view-cell aui-img aui-col-xs-4  aui-padded-5' style='margin-left: 5px;width:" + normalW + "px;height:" + normalW + "px;' onclick='lookImg(\"" + imgUrl + "\")'><img class='aui-img-object' src='" + imgUrl +
                                "' style='width:" + normalW + "px;height:" + normalW + "px;'></li>";
                            $("#addpic").before(showImgHtml);
                        }
                    }
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    // 为图片添加点击预览功能,排除添加按钮
    function lookImg(compressImg) {
        // 定义一个数组，存储需要预览的图片
        var browerImgs = [];
        // 调用图片预览函数
        browerImgs.push(compressImg);
        openImageBrowser(browerImgs);
    }

    // 上传图片
    // url：上传的url地址
    // data：上传的文件
    // callback：上传成功返回地址
    function uploadFile(data) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uploadPhotosAPP";
        var data = {
            values: {
                un: un
            },
            files: {
                file: data
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == "0") {
                    console.log("上传成功");
                } else if (myobj.code == "1") {
                    alert("上传失败");
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>